package com.proyecto.track.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.proyecto.track.bo.Period;

public class PeriodDAOImp implements PeriodDAO{
	
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public Long createPeriod(Period period) {
		sessionFactory.getCurrentSession().save(period);
		return period.getId();
	}

	@Override
	public Long deletePeriod(Period period) {
		Long id = period.getId();
		sessionFactory.getCurrentSession().delete(period);
		return id;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Period> searchPeriod() {
		return  sessionFactory.getCurrentSession().createQuery("from Period").list();
	}

	@Override
	public Period searchPeriod(Long id) {
		return (Period) sessionFactory.getCurrentSession().get(Period.class, id);
	}

}
